package studentinformationmanagementsystem.dao.impl;

import studentinformationmanagementsystem.dao.BaseDao;
import studentinformationmanagementsystem.dao.DepartmentDao;
import studentinformationmanagementsystem.entity.Course;
import studentinformationmanagementsystem.entity.Department;

import java.util.List;

/**
 * @author 苗庆
 * @version 1.0
 */
public class DepartmentDaolmpl  extends BaseDao implements DepartmentDao {


    /**
     * 对院系信息进行添加
     * @param department  院系对象
     * @return  受影响的记录行数
     */
    @Override
    public int insert(Department department) {
        String sql = "INSERT INTO `t_departmentid` (`department`, `departmentction`) VALUES (?, ?)";
        return super.update(sql,department.getDepartment(),department.getDepartmentction());
    }


    /**
     *  根据ID更新院系信息
     * @param department  院系对象
     * @return 受影响的记录行数
     */
    @Override
    public int update(Department department) {
        String sql = "UPDATE `t_departmentid` SET `department` = ? , `departmentction` = ? WHERE `departmentid` = ? ";
        return super.update(sql,department.getDepartment(),department.getDepartmentction(),department.getDepartmentid());
    }


    /**
     *  根据ID删除院系
     * @param department 院系ID
     * @return 受影响的记录行数
     */
    @Override
    public int delete(Department department) {
        String sql = "DELETE FROM `t_departmentid` WHERE `departmentid` = ?";
        return super.update(sql, department.getDepartmentid());
    }

    /**
     * 查询所有院系信息
     * @return 所有院系信息
     */
    @Override
    public List<Department> queryAll() {
        String sql = "SELECT * FROM `t_departmentid`";
        return super.queryForList(Department.class, sql);
    }


    /**
     * 根据院系ID查询院系信息
     * @param department 院系ID
     * @return 院系信息
     */
    @Override
    public Department queryById(Department department) {
        String sql = "SELECT * FROM `t_departmentid` WHERE `departmentid` = ?";
        return super.queryForOne(Department.class, sql, department.getDepartmentid());
    }


    /**
     * 根据院系名称查询院系信息
     * @param department 院系名称
     * @return 院系信息
     */
    @Override
    public Department queryBydepartmentNname(Department department) {
        String sql = "SELECT * FROM `t_departmentid` WHERE `department` = ?";
        return super.queryForOne(Department.class, sql, department.getDepartment());
    }

    /**
     * 查询总记录条数
     */
    @Override
    public Integer queryForPageTotalCount() {
        String sql = "SELECT COUNT(1) FROM `t_departmentid`";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    /**
     * 分页查询DAO层方法
     *
     * @param begin    起始记录行数
     * @param pageSize 每页展示数量
     * @return
     */
    @Override
    public List<Department> queryForPageItems(int begin, int pageSize) {
        String sql = "SELECT * FROM `t_departmentid` LIMIT ?, ?";
        return super.queryForList(Department.class, sql, begin, pageSize);
    }
}
